package com.cloudptt.wp.ui.message;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import com.cloudptt.api.product.log.Log;
import com.cloudptt.wp.R;
import com.cloudptt.wp.ScreenManager;
import com.cloudptt.wp.ui.BaseActivity;
import com.cloudptt.wp.ui.FragmentInfo;
import com.cloudptt.wp.ui.address.AddrGroupFragment;
import com.cloudptt.wp.ui.address.AddrUserFragment;
import com.cloudptt.wp.ui.address.adapter.MyPagerAdapter;
import com.google.android.material.tabs.TabLayout;
import com.mcptt.db.model.SessionInfo;

import java.util.ArrayList;
import java.util.List;

public class ForwardMsgActivity extends BaseActivity {
    public static final String KEY = "forward";
    private ArrayList<SessionInfo> sessionList = new ArrayList<>();
    private SessionInfo sessionInfo = null;
    private List<FragmentInfo> fragments = new ArrayList<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.setStatusBarColor(getResources().getColor(R.color.white));
        // 使用 ImmersionBar 示例
        setContentView(R.layout.activity_msg_forward);
        Log.debug(this.getClass(),"onCreate savedInstanceState = " + savedInstanceState);
        initNotificationLayout();

        sessionList = getIntent().getParcelableArrayListExtra(ForwardMsgActivity.KEY);
        Log.debug(this.getClass(),"onCreate sessionList = " + sessionList);
//        sessionInfo = (SessionInfo) getIntent().get(ForwardMsgActivity.KEY);
//        Log.debug(this.getClass(),"onCreate sessionInfo = " + sessionInfo);
//        sessionList.add(sessionInfo);

//        ImageView backup_btn = (ImageView) findViewById(R.id.back_up_icon);
//        backup_btn.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                // TODO Auto-generated method stub
//                ScreenManager.getScreenManager().popActivity();
//                overridePendingTransition(R.anim.in_from_right, R.anim.out_to_left);
//            }
//        });

        ViewPager viewPager = findViewById(R.id.viewPager);
        TabLayout tabLayout = findViewById(R.id.tabLayout);
//		tabLayout.setTabTextColors(R.color.white,R.color.black);
        for (int i = 0; i < tabLayout.getTabCount(); i++)
        {
            TabLayout.Tab tab = tabLayout.getTabAt(i);
            if (tab != null)
            {
                TextView tabView = (TextView) LayoutInflater.from(this).inflate(R.layout.tab_custom, null);
                tabView.setText(tab.getText());
                tab.setCustomView(tabView);
            }
        }
        AddrGroupFragment groupFg = new AddrGroupFragment(this,null,true,sessionList);
        fragments.add(new FragmentInfo("群组",groupFg));
        AddrUserFragment userFg = new AddrUserFragment(this,false,true,sessionList);
        fragments.add(new FragmentInfo("个人",userFg));

        // 自定义适配器继承 FragmentPagerAdapter（兼容旧版本）
        MyPagerAdapter adapter = new MyPagerAdapter(getSupportFragmentManager(),fragments);
        viewPager.setAdapter(adapter);
        tabLayout.setupWithViewPager(viewPager);
    }

    @Override
    protected void onResume() {
        super.onResume();
    }
}
